/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
 */

package com.huawei.fastble.adapter;

import com.huawei.fastble.ResourceTable;
import com.huawei.fastble.slice.MainAbilitySlice;

import com.clj.fastble.data.BleDevice;

import ohos.agp.components.*;
import ohos.app.Context;
import ohos.bluetooth.ble.GattService;

import java.util.List;

/**
 * serviceItemProvider extends BaseItemProvider
 *
 */
public class ServiceItemProvider extends BaseItemProvider {
    private Context context;

    private List<GattService> gattServiceList;

    public ServiceItemProvider(Context context, List<GattService> itemList) {
        this.context = context;
        gattServiceList = itemList;
    }

    @Override
    public int getCount() {
        return gattServiceList.size();
    }

    @Override
    public Object getItem(int position) {
        return gattServiceList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public Component getComponent(int position, Component component, ComponentContainer componentContainer) {
        return getRootView(position);
    }

    private Component getRootView(int position) {
        Component rootView =
                LayoutScatter.getInstance(context).parse(ResourceTable.Layout_service_item_layout, null, false);
        Text txtTitle = (Text) rootView.findComponentById(ResourceTable.Id_txt_title);
        Text txtUUID = (Text) rootView.findComponentById(ResourceTable.Id_txt_uuid);

        GattService service = gattServiceList.get(position);

        // 制造商
        txtTitle.setText("服务：" + position);
        txtUUID.setText("UUID:" + service.getUuid().toString());

        return rootView;
    }
}
